package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-04 21:20
 **/
public class JianZhiOffer54 {

    int k;
    int val;

    public int kthLargest(TreeNode root, int k) {
        this.k = k;
        dfs(root);
        return val;
    }

    private void dfs(TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(root.right);
        if (k == 0) {
            return;
        }
        if (--k == 0) {
            val = root.val;
        }
        dfs(root.left);
    }

}
